package com.zrrd.mcl.webll.controller;

import com.zrrd.mcl.cart.client.CartFeignClient;
import com.zrrd.mcl.model.product.SkuInfo;
import com.zrrd.mcl.product.client.ProductFeiginClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

@Controller
public class CartController {

    @Autowired
    private CartFeignClient cartFeignClient;
    @Autowired
    private ProductFeiginClient productFeiginClient;

    //添加购物车
    @RequestMapping("addCart.html")
    public String addCart(@RequestParam("skuId") Long skuId,
                          @RequestParam("skuNum") Integer skuNum,
                          HttpServletRequest request) {
        cartFeignClient.addToCart(skuId, skuNum);
        SkuInfo skuInfo = productFeiginClient.getSkuInfo(skuId);
        request.setAttribute("skuInfo", skuInfo);
        request.setAttribute("skuNum", skuNum);
        return "cart/addCart";
    }

    //查询购物车
    @RequestMapping("cart.html")
    public String index(){
        return "cart/index";
    }

}
